package Gui;
/**
 * this class implements gui of return reports
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
import java.util.Date;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;

import Logic.LoginInfo;

import client.LibaryMain;
import javax.swing.ImageIcon;
/**
 * this class implements gui lending window 
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class LendingGui extends JPanel {
	private JTextField idtextf;
	private JTextField bookid;
	private String idtext,book;
	public LendingGui() {
		setBackground(new Color(153, 204, 255));
		init();
	}
	  /**
	 * this function create instance of Lending gui 
	 */
    
		public void init(){
		
		JLabel lblNewLabel = new JLabel("Lending Book");
		lblNewLabel.setBounds(87, 41, 272, 32);
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 26));
		
		JLabel lblSubscriberid = new JLabel("SubscriberID");
		lblSubscriberid.setBounds(184, 275, 104, 20);
		lblSubscriberid.setFont(new Font("Tahoma", Font.BOLD, 16));
		
		JLabel lblBookcopyid = new JLabel("BookCopyID");
		lblBookcopyid.setBounds(184, 323, 100, 20);
		lblBookcopyid.setFont(new Font("Tahoma", Font.BOLD, 16));
		
		idtextf = new JTextField();
		idtextf.setBounds(340, 274, 210, 27);
		idtextf.setColumns(10);
		
		bookid = new JTextField();
		bookid.setBounds(340, 320, 210, 25);
		bookid.setColumns(10);
		
		JButton btnLend = new JButton("Lend");
		btnLend.setBounds(367, 381, 148, 39);
		btnLend.setFont(new Font("Tahoma", Font.BOLD, 14));
		
		btnLend.addActionListener(new java.awt.event.ActionListener() {     // Login action listener 
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	btnLendActionPerformed(evt);
            
            }

		private void btnLendActionPerformed(ActionEvent evt) {
			idtext=null;
			book=null;
			String idtext=idtextf.getText();
            String book=bookid.getText();
				if(idtext.equals(""))
					JOptionPane.showMessageDialog(null, "Please enter Subscriber ID");
            			if(book.equals(""))
            				JOptionPane.showMessageDialog(null, "Please enter book ID");
						ArrayList<String> Arr=new ArrayList<String>();
						Arr.add("LendBook");
            			Arr.add(idtext);
						Arr.add(book);
						LibaryMain.chat.handleMessageFromGui(Arr);
    		
			
		}
        });
		
		JButton btnBack = new JButton("Back");
		btnBack.setBounds(85, 563, 80, 25);
		btnBack.setFont(new Font("Tahoma", Font.BOLD, 14));
		
		btnBack.addActionListener(new java.awt.event.ActionListener() {     
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnback(ev);
            					
			}

			private void btnback(ActionEvent ev) {
				MainScreen.cardLayot.show(MainScreen.card, DirectorWindow.roll);
				
			}
        });
		
		JButton btnLogout = new JButton("LogOut");
		btnLogout.setBounds(647, 563, 85, 25);
		btnLogout.setFont(new Font("Tahoma", Font.BOLD, 14));
		
		btnLogout.addActionListener(new java.awt.event.ActionListener() {      
            public void actionPerformed(java.awt.event.ActionEvent ev) {
            	btnLogOut(ev);
            					
			}

			private void btnLogOut(ActionEvent ev) {
				ArrayList<String> Arr=new ArrayList<String>();
				Arr.add("Logout");
				Arr.add("Worker");
				Arr.add(LoginInfo.UserName);
				LibaryMain.chat.handleMessageFromGui(Arr);
				MainScreen.cardLayot.show(MainScreen.card, "Login");
				
			}
        });
		setLayout(null);
		add(btnLend);
		add(lblNewLabel);
		add(btnBack);
		add(btnLogout);
		add(lblSubscriberid);
		add(lblBookcopyid);
		add(bookid);
		add(idtextf);
		
		JLabel label = new JLabel("");
		label.setIcon(new ImageIcon(LendingGui.class.getResource("/Gui/images/book.png")));
		label.setBounds(206, 11, 602, 541);
		add(label);
	}
}
